import os
import yaml

def backup_configs(log_dir, data_paths, feat_configs, opt_configs):
    os.makedirs(log_dir, exist_ok=True)
    # Clean empty log dir if no ckpt file exist
    with open(log_dir + "/data_paths.yaml", "w") as f:
        yaml.safe_dump(data_paths, f)
    with open(log_dir + "/feat.yaml", "w") as f:
        yaml.safe_dump(feat_configs, f)
    with open(log_dir + "/opt.yaml", "w") as f:
        yaml.safe_dump(opt_configs, f)
    # Copy /home/shaonian/SED/sssl_sed/codes/training/domain_agnostic_trainer.py to the log dir
    os.system(f"cp /home/shaonian/SED/sssl_sed/codes/training/domain_agnostic_trainer.py {log_dir}")